<!DOCTYPE html>
<html>

<head>
    <title>病房智慧信息系统 </title>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Pragma" content="no-cache"/>
    <META http-equiv="Cache-Control" content="no-cache, must-revalidate">
    <META http-equiv="expires" content="0">
    <link rel="stylesheet" href="assets/libs/layui/css/layui.min.css?v=1"/>
    <link rel="stylesheet" href="assets/css/login.min.css?v=1" media="all">
    <style>
        body {
            background-image: none !important;
        }
    </style>
</head>

<body>
<div class="login-wrapper">
    <div class=" login-body">
        <div class="layui-card">
            <div class="layui-card-header login-title">
                用户登录
            </div>
            <form class="layui-card-body layui-form layui-form-pane login-form">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                    <div class="layui-input-block">
                        <input name="username" type="text" lay-verify="required" placeholder="账号" value="admin"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" style="padding-top:20px;">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-password"></i></label>
                    <div class="layui-input-block">
                        <input name="password" type="password" lay-verify="required" placeholder="密码" value="123456"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" style="padding-top:30px;padding-bottom: 30px">
                    <button type="button" lay-filter="login-submit" class="layui-btn layui-btn-fluid" style="background-color:#5a8bff;" lay-submit>
                        登 录
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript" src="assets/libs/layui/layui.min.js?v=1" charset="UTF-8"></script>
<script src="assets/js/layui-config.min.js?v=1" charset="UTF-8"></script>
<script>
    layui.config({
        base: 'assets/module/'
    }).use(['jquery','http', 'form','md5'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var http = layui.http;

        // 表单提交
        form.on('submit(login-submit)', function (obj) {
            var field = obj.field;
            field.password = $.md5(field.password).toUpperCase();
            layer.load(2);
            $.ajax({
                url: '/api/user/login',
                data: field,
                type: 'POST',
                dataType: 'JSON',
                timeout: 40000,
                success: function (data) {
                    layer.closeAll('loading');
                    //alert(JSON.stringify(data));
                    //console.log(data);
                    if (data.data) {
                        http.putToken(data.data);
                        layer.msg('登录成功', {icon: 1, time: 1000}, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg('登录失败，请重试', {icon: 5});
                    }
                },
                error: function (xhr) {
                    layer.closeAll('loading');
                    if (xhr.status == 401 || xhr.status == 400) {
                        layer.msg('登录超时或无权访问', {icon: 5});
                    }else if(xhr.status == 403){
                        layer.msg("账号或密码错误",{icon:5});
                    }else{
                        layer.msg(xhr.statusText || '连接到服务器有错');
                    }
                },
                complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
                    layer.closeAll('loading');
                    if (status == 'timeout') {//超时,status还有success,error等值的情况
                        //ajax && ajax.abort();
                        http.failMsg("超时");
                    }
                }

            });
        });

    });
</script>
</body>
</html>